<template>
  <div id="waveplansmaintenance">
    <v-tableTitle
      :btnConfig="btnData"
      :title="$t('wave.waveplanmgmt')"
      @newCreate="newCreate"
      @del="del"
      @check="check"
    >
    </v-tableTitle>
    <ag-grid
      class="base-grid"
      :hasCheck="true"
      :hasIndex="false"
      :hasEdit="true"
      v-model="gridObj"
      :defaultColDef="defaultColDef"
      :highlightCurrentRow="false"
      :disabled="true"
      :data="rowData"
      :rules="rules"
      :height="height"
      :tmsShowFilter="true"
      :columnConfig="columnConfig"
      :extraColumns="extraColumns"
      :showSummary="false"
      :pagination="true"
      :tableSettingVisible.sync="showTableSetting"
      :page="page"
      :pageSize="pageSize"
      :total="total"
      @selection-change="handleSelectionChange"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      @setdialog="setdialog"
      @filter-changed="filterChanged"
      @cell-dblclick="cellDblclick"
      @grid-ready="agGridReady"
    >
    </ag-grid>
  </div>
</template>

<script>
import agGridBaseMixin from "@/mixins/AgGridBaseMixin";
import Config from "./Config";
import {
  getOutWaveStrategyPlanList,
  outWaveStrategyPlanDelete,
} from "@/api/business/wave";
import baseMixin from "@/mixins/BaseMixin";
export default {
  name: "waveplansmaintenance",
  mixins: [baseMixin,agGridBaseMixin, Config],
  data() {
    return {
      week: 0,
      timeNow: "",
      height: 0,
      columnConfig: {
        menu_id: 948,
        menu_code: "waveplansmaintenance",
        menu_list_code: "waveplansmaintenance",
      },
      defaultColDef: {},
    };
  },
  mounted() {
    ;
    this.$store.commit("setSkip", {});
    this.$store.commit("setRouteId", "");
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setRouteData", {});
    this.getTableData(1, this.pageSize, {});
    this.height = this.getHeight(window, 70);
    this.width = (window.innerWidth - 280 - 48) / 7;
  },
  computed: {
    btnData() {
      return [
        {
          label: this.$t("common.create"),
          certigier: this.newStatus||!this.btnPermNameList.includes('WM05010301'),
          invalid: "newCreate",
        },
        {
          label: this.$t("common.delete"),
          certigier: this.delStatus||!this.btnPermNameList.includes('WM05010302'),
          invalid: "del",
        },
        { label:this.$t("common.check"), certigier: this.checkStatus||!this.btnPermNameList.includes('WM05010303'), invalid: "check" },
      ];
    },
  },
  methods: {
    newCreate() {
      this.$store.commit("setNewFlag", true);
      this.$router.push({ name: "waveplansmaintenanceDeawer" });
    },
    deleteData(data) {
      outWaveStrategyPlanDelete(data).then((res) => {
          this.$message.success(res.returnMgr);
          this.getTableData(1, this.pageSize, {});
        
      });
    },
    del() {
      let arr = this.gridObj.api.getSelectedRows();
      let data = [];
      if (arr.length === 0) {
        this.$message.error(this.$t('msg.msg12'));
        return;
      }
      if (arr.length !== 1) {
        this.$message.error(this.$t('msg.msg32'));
        return;
      }
      arr.forEach((item, i) => {
        if (item.wavePlanStatus === "已完成") {
          this.$message.error(`不能删除状态为已完成的计划!`);
          return;
        } else if (item.wavePlanStatus === "执行中") {
          this.$confirm(`选中数据状态为执行中,确认删除吗?`, "", {
            confirmButtonText: this.$t("common.confirm"),
            cancelButtonText: this.$t("common.cancel"),
          })
            .then(() => {
              data.push({ id: item.id });
              this.deleteData(data);
            })
            .catch(() => {
              return;
            });
        } else if (item.wavePlanStatus === "待执行") {
          data.push({ id: item.id });
          this.deleteData(data);
        }
      });
    },
    check() {
      this.$router.push({ name: "waveplanpanel" });
    },
    setdialog(data) {
      console.log(data);
      this.$store.commit("setRouteData", data);
      this.$router.push({ name: "waveplansmaintenanceDeawer" });
    },
    getTableData(page, pageSize, data) {
      getOutWaveStrategyPlanList(page, data).then((res) => {
          this.rowData = res.page.list;
          this.page = res.page.currentPage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      });
    },
  },
};
</script>

<style lang="scss" scoped>
#waveplansmaintenance {
  overflow: hidden;
}
</style>
